/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * bzr_neueVeranstaltung.java
 *
 * Created on 14.05.2011, 13:44:42
 */
package Anwendung;

import bzr_lagerverwaltung.GiveAway;
import bzr_lagerverwaltung.Werbemittel;
import bzr_veranstaltungverwaltung.Mitarbeiter;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;

/**
 *
 * @author Flo
 */
public class bzr_neueVeranstaltung extends javax.swing.JFrame {

    /** Creates new form bzr_neueVeranstaltung */
    public DefaultComboBoxModel dcbm;
    public Connection con;
    public DefaultListModel dlm_MA;
    public DefaultListModel dlm_aus;
    public DefaultListModel dlm_werbemittel;
    public DefaultListModel dlm_aus_werbemittel;
    public DefaultListModel dlm_ga;
    public DefaultListModel dlm_aus_ga;
    public DefaultListModel dlm_ansprechpersonen;

    public bzr_neueVeranstaltung() {
        
        verbindenDB();
        initComponents();
        initJSpinners();
        initComboBox();
        initListMA();
        initWerbemittelGiveAways();
        dlm_aus = new DefaultListModel();
        jListAusgewaehlteMA.setModel(dlm_aus);
        dlm_aus_werbemittel = new DefaultListModel();
        jListausgehwaehlteW.setModel(dlm_aus_werbemittel);
        dlm_aus_ga = new DefaultListModel();
        jListausgewaehlteG.setModel(dlm_aus_ga);
        dlm_ansprechpersonen = new DefaultListModel();
        jListAnsprechpersonen.setModel(dlm_ansprechpersonen);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton_VAanlegen = new javax.swing.JButton();
        jTabbedPaneVA = new javax.swing.JTabbedPane();
        jPanelAllgemein = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldName = new javax.swing.JTextField();
        jTextFieldStraße = new javax.swing.JTextField();
        jTextFieldZustaendigeGeschaeftsstelle = new javax.swing.JTextField();
        jTextFieldOrt = new javax.swing.JTextField();
        jFormattedTextFieldPLZ = new javax.swing.JFormattedTextField();
        jFormattedTextFieldHnr = new javax.swing.JFormattedTextField();
        jSpinnerStartDatum = new javax.swing.JSpinner();
        jSpinnerEndDatum = new javax.swing.JSpinner();
        jPanelMA = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jComboBoxBezirk = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jComboBoxFuehrerschein = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListMA = new javax.swing.JList();
        jButtonVerschieben = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jListAusgewaehlteMA = new javax.swing.JList();
        jPanelWerbemittel = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jListWerbemittel = new javax.swing.JList();
        jScrollPane5 = new javax.swing.JScrollPane();
        jListausgehwaehlteW = new javax.swing.JList();
        jButtonVerschiebenWerbemittel = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        jListGiveAways = new javax.swing.JList();
        jButtonVerschiebenGiveAways = new javax.swing.JButton();
        jScrollPane7 = new javax.swing.JScrollPane();
        jListausgewaehlteG = new javax.swing.JList();
        jLabel11 = new javax.swing.JLabel();
        jPanelAnsprechperson = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jTextFieldVName = new javax.swing.JTextField();
        jTextFieldNName = new javax.swing.JTextField();
        jTextFieldEmail = new javax.swing.JTextField();
        jFormattedTextFieldTelNum = new javax.swing.JFormattedTextField();
        jButtonHinzu = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        jListAnsprechpersonen = new javax.swing.JList();
        jPanelInfo = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextAreaInfos = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton_VAanlegen.setText("Veranstaltung anlegen");
        jButton_VAanlegen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_VAanlegenActionPerformed(evt);
            }
        });

        jLabel1.setText("Name:");

        jLabel2.setText("PLZ:");

        jLabel3.setText("Straße:");

        jLabel4.setText("Ort:");

        jLabel8.setText("HausNr.:");

        jLabel10.setText("Geschäftsstelle:");

        jLabel12.setText("Enddatum:");

        jLabel13.setText("Startdatum:");

        jSpinnerStartDatum.setModel(new javax.swing.SpinnerDateModel());

        jSpinnerEndDatum.setModel(new javax.swing.SpinnerDateModel());

        javax.swing.GroupLayout jPanelAllgemeinLayout = new javax.swing.GroupLayout(jPanelAllgemein);
        jPanelAllgemein.setLayout(jPanelAllgemeinLayout);
        jPanelAllgemeinLayout.setHorizontalGroup(
            jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAllgemeinLayout.createSequentialGroup()
                .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelAllgemeinLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13)
                            .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(26, 26, 26)
                .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldZustaendigeGeschaeftsstelle, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSpinnerEndDatum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldOrt, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextFieldHnr, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldStraße, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextFieldPLZ, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSpinnerStartDatum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(294, Short.MAX_VALUE))
        );
        jPanelAllgemeinLayout.setVerticalGroup(
            jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAllgemeinLayout.createSequentialGroup()
                .addGap(54, 54, 54)
                .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldOrt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelAllgemeinLayout.createSequentialGroup()
                        .addComponent(jFormattedTextFieldPLZ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldStraße, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jFormattedTextFieldHnr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(18, 18, 18)
                .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jSpinnerStartDatum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jSpinnerEndDatum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelAllgemeinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTextFieldZustaendigeGeschaeftsstelle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        jTabbedPaneVA.addTab("Allgemein", jPanelAllgemein);

        jLabel5.setText("Bezirk:");

        jComboBoxBezirk.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxBezirkItemStateChanged(evt);
            }
        });

        jLabel6.setText("Führerschein:");

        jComboBoxFuehrerschein.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ja", "Nein" }));
        jComboBoxFuehrerschein.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxFuehrerscheinItemStateChanged(evt);
            }
        });

        jScrollPane1.setViewportView(jListMA);

        jButtonVerschieben.setText("-->");
        jButtonVerschieben.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVerschiebenActionPerformed(evt);
            }
        });

        jScrollPane2.setViewportView(jListAusgewaehlteMA);

        javax.swing.GroupLayout jPanelMALayout = new javax.swing.GroupLayout(jPanelMA);
        jPanelMA.setLayout(jPanelMALayout);
        jPanelMALayout.setHorizontalGroup(
            jPanelMALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelMALayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelMALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelMALayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31)
                        .addComponent(jButtonVerschieben)
                        .addGap(10, 10, 10)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE))
                    .addGroup(jPanelMALayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(41, 41, 41)
                        .addComponent(jComboBoxBezirk, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelMALayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxFuehrerschein, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanelMALayout.setVerticalGroup(
            jPanelMALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelMALayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelMALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelMALayout.createSequentialGroup()
                        .addComponent(jButtonVerschieben)
                        .addGap(123, 123, 123))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelMALayout.createSequentialGroup()
                        .addGroup(jPanelMALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jComboBoxBezirk, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelMALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jComboBoxFuehrerschein, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelMALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE))
                        .addContainerGap())))
        );

        jTabbedPaneVA.addTab("Mitarbeiter", jPanelMA);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel7.setText("Werbemittel");

        jScrollPane4.setViewportView(jListWerbemittel);

        jScrollPane5.setViewportView(jListausgehwaehlteW);

        jButtonVerschiebenWerbemittel.setText("-->");
        jButtonVerschiebenWerbemittel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVerschiebenWerbemittelActionPerformed(evt);
            }
        });

        jScrollPane6.setViewportView(jListGiveAways);

        jButtonVerschiebenGiveAways.setText("-->");
        jButtonVerschiebenGiveAways.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVerschiebenGiveAwaysActionPerformed(evt);
            }
        });

        jScrollPane7.setViewportView(jListausgewaehlteG);

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel11.setText("Give Aways");

        javax.swing.GroupLayout jPanelWerbemittelLayout = new javax.swing.GroupLayout(jPanelWerbemittel);
        jPanelWerbemittel.setLayout(jPanelWerbemittelLayout);
        jPanelWerbemittelLayout.setHorizontalGroup(
            jPanelWerbemittelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelWerbemittelLayout.createSequentialGroup()
                .addGroup(jPanelWerbemittelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelWerbemittelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonVerschiebenWerbemittel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelWerbemittelLayout.createSequentialGroup()
                        .addGap(79, 79, 79)
                        .addComponent(jLabel7)))
                .addGroup(jPanelWerbemittelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelWerbemittelLayout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonVerschiebenGiveAways)
                        .addGap(6, 6, 6)
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelWerbemittelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel11)
                        .addGap(103, 103, 103))))
        );
        jPanelWerbemittelLayout.setVerticalGroup(
            jPanelWerbemittelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelWerbemittelLayout.createSequentialGroup()
                .addGap(106, 106, 106)
                .addComponent(jButtonVerschiebenWerbemittel)
                .addContainerGap(186, Short.MAX_VALUE))
            .addGroup(jPanelWerbemittelLayout.createSequentialGroup()
                .addGap(111, 111, 111)
                .addComponent(jButtonVerschiebenGiveAways)
                .addContainerGap(181, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelWerbemittelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelWerbemittelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelWerbemittelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE))
                .addGap(94, 94, 94))
        );

        jTabbedPaneVA.addTab("Werbemittel", jPanelWerbemittel);

        jLabel9.setText("Vorname");

        jLabel14.setText("Nachname");

        jLabel15.setText("Telefonnummer");

        jLabel16.setText("E-Mail");

        jButtonHinzu.setText("Hinzufügen");
        jButtonHinzu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonHinzuActionPerformed(evt);
            }
        });

        jListAnsprechpersonen.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane8.setViewportView(jListAnsprechpersonen);

        javax.swing.GroupLayout jPanelAnsprechpersonLayout = new javax.swing.GroupLayout(jPanelAnsprechperson);
        jPanelAnsprechperson.setLayout(jPanelAnsprechpersonLayout);
        jPanelAnsprechpersonLayout.setHorizontalGroup(
            jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAnsprechpersonLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelAnsprechpersonLayout.createSequentialGroup()
                        .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelAnsprechpersonLayout.createSequentialGroup()
                                .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel14))
                                .addGap(27, 27, 27)
                                .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldNName)
                                    .addComponent(jTextFieldVName, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)))
                            .addGroup(jPanelAnsprechpersonLayout.createSequentialGroup()
                                .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel15)
                                    .addComponent(jLabel16))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                                    .addComponent(jFormattedTextFieldTelNum, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE))))
                        .addGap(60, 60, 60))
                    .addGroup(jPanelAnsprechpersonLayout.createSequentialGroup()
                        .addComponent(jButtonHinzu)
                        .addGap(168, 168, 168)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31))
        );
        jPanelAnsprechpersonLayout.setVerticalGroup(
            jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAnsprechpersonLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelAnsprechpersonLayout.createSequentialGroup()
                        .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jTextFieldVName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(jTextFieldNName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel15)
                            .addComponent(jFormattedTextFieldTelNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelAnsprechpersonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jButtonHinzu)))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        jTabbedPaneVA.addTab("Ansprechperson", jPanelAnsprechperson);

        jTextAreaInfos.setColumns(20);
        jTextAreaInfos.setRows(5);
        jScrollPane3.setViewportView(jTextAreaInfos);

        javax.swing.GroupLayout jPanelInfoLayout = new javax.swing.GroupLayout(jPanelInfo);
        jPanelInfo.setLayout(jPanelInfoLayout);
        jPanelInfoLayout.setHorizontalGroup(
            jPanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(188, Short.MAX_VALUE))
        );
        jPanelInfoLayout.setVerticalGroup(
            jPanelInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(76, Short.MAX_VALUE))
        );

        jTabbedPaneVA.addTab("Infos", jPanelInfo);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(535, 535, 535)
                        .addComponent(jButton_VAanlegen))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPaneVA, javax.swing.GroupLayout.PREFERRED_SIZE, 616, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(147, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPaneVA, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_VAanlegen, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxBezirkItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxBezirkItemStateChanged
        // TODO add your handling code here:
        initListMA();
    }//GEN-LAST:event_jComboBoxBezirkItemStateChanged

    private void jComboBoxFuehrerscheinItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxFuehrerscheinItemStateChanged
        // TODO add your handling code here:
        initListMA();
    }//GEN-LAST:event_jComboBoxFuehrerscheinItemStateChanged

    private void jButtonVerschiebenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVerschiebenActionPerformed
        // TODO add your handling code here:

        for (int i = 0; i < jListMA.getSelectedValues().length; i++) {
            dlm_aus.addElement(jListMA.getSelectedValues()[i]);
        }
    }//GEN-LAST:event_jButtonVerschiebenActionPerformed

    private void jButtonVerschiebenWerbemittelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVerschiebenWerbemittelActionPerformed
        try {
            // TODO add your handling code here:
            Statement st = (Statement) con.createStatement();
            ResultSet rs = (ResultSet) st.executeQuery("SELECT  Ist_Stueckzahl FROM Aussenwerbemittel_Art WHERE Aussenwerbemittel_Art='" + jListWerbemittel.getSelectedValue() + "'");
            int ist = 0;
            while (rs.next()) {
                ist = rs.getInt("Ist_Stueckzahl");
            }
            int c = Integer.parseInt(JOptionPane.showInputDialog("Wie viele Stück wollen sie nehmen?  (" + ist + ") Vorhanden", "0"));
            Werbemittel w = new Werbemittel();
            w.setArt(jListWerbemittel.getSelectedValue().toString());
            w.setIst_stueckzahl(ist);
            dlm_aus_werbemittel.addElement(w);
        } catch (Exception ex) {
        }
    }//GEN-LAST:event_jButtonVerschiebenWerbemittelActionPerformed

    private void jButtonVerschiebenGiveAwaysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVerschiebenGiveAwaysActionPerformed
        // TODO add your handling code here:
        try {
            // TODO add your handling code here:
            Statement st = (Statement) con.createStatement();
            ResultSet rs = (ResultSet) st.executeQuery("SELECT  Ist_Stueckzahl FROM GiveAways WHERE Name='" + jListGiveAways.getSelectedValue() + "'");
            int ist = 0;
            while (rs.next()) {
                ist = rs.getInt("Ist_Stueckzahl");
            }
            int c = Integer.parseInt(JOptionPane.showInputDialog("Wie viele Stück wollen sie nehmen?  (" + ist + ") Vorhanden", "0"));
            GiveAway g = new GiveAway();
            g.setName(jListGiveAways.getSelectedValue().toString());
            g.setIst_stueckzahl(ist);
            dlm_aus_ga.addElement(g);
        } catch (Exception ex) {
        }
    }//GEN-LAST:event_jButtonVerschiebenGiveAwaysActionPerformed

    private void jButtonHinzuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonHinzuActionPerformed
        // TODO add your handling code here:
        Ansprechperson a = new Ansprechperson();
        a.setVorname(jTextFieldVName.getText());
        a.setNachname(jTextFieldNName.getText());
        a.setEmail(jTextFieldEmail.getText());
        a.setTelNum(Integer.parseInt(jFormattedTextFieldTelNum.getText()));
        dlm_ansprechpersonen.addElement(a);
    }//GEN-LAST:event_jButtonHinzuActionPerformed

    private void jButton_VAanlegenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_VAanlegenActionPerformed
        // TODO add your handling code here:
        InsertAllgemein();
        InsertMitarbeiter();
        InsertWerbemittel();
        this.setVisible(false);
    }//GEN-LAST:event_jButton_VAanlegenActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new bzr_neueVeranstaltung().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonHinzu;
    private javax.swing.JButton jButtonVerschieben;
    private javax.swing.JButton jButtonVerschiebenGiveAways;
    private javax.swing.JButton jButtonVerschiebenWerbemittel;
    private javax.swing.JButton jButton_VAanlegen;
    private javax.swing.JComboBox jComboBoxBezirk;
    private javax.swing.JComboBox jComboBoxFuehrerschein;
    private javax.swing.JFormattedTextField jFormattedTextFieldHnr;
    private javax.swing.JFormattedTextField jFormattedTextFieldPLZ;
    private javax.swing.JFormattedTextField jFormattedTextFieldTelNum;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jListAnsprechpersonen;
    private javax.swing.JList jListAusgewaehlteMA;
    private javax.swing.JList jListGiveAways;
    private javax.swing.JList jListMA;
    private javax.swing.JList jListWerbemittel;
    private javax.swing.JList jListausgehwaehlteW;
    private javax.swing.JList jListausgewaehlteG;
    private javax.swing.JPanel jPanelAllgemein;
    private javax.swing.JPanel jPanelAnsprechperson;
    private javax.swing.JPanel jPanelInfo;
    private javax.swing.JPanel jPanelMA;
    private javax.swing.JPanel jPanelWerbemittel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JSpinner jSpinnerEndDatum;
    private javax.swing.JSpinner jSpinnerStartDatum;
    private javax.swing.JTabbedPane jTabbedPaneVA;
    private javax.swing.JTextArea jTextAreaInfos;
    private javax.swing.JTextField jTextFieldEmail;
    private javax.swing.JTextField jTextFieldNName;
    private javax.swing.JTextField jTextFieldName;
    private javax.swing.JTextField jTextFieldOrt;
    private javax.swing.JTextField jTextFieldStraße;
    private javax.swing.JTextField jTextFieldVName;
    private javax.swing.JTextField jTextFieldZustaendigeGeschaeftsstelle;
    // End of variables declaration//GEN-END:variables

    private void verbindenDB() {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            String url = "jdbc:mysql://mysql.bezirksrundschau.com:3306/brdbm_1";
            con = (Connection) DriverManager.getConnection(url, "brdbm", "br2011!db");
        } catch (Exception ex) {
        }
    }

    private void initJSpinners() {
        JComponent editor_start = new JSpinner.DateEditor(jSpinnerStartDatum, "dd.MM.yyyy");
        jSpinnerStartDatum.setEditor(editor_start);
        JComponent editor_end = new JSpinner.DateEditor(jSpinnerEndDatum, "dd.MM.yyyy");
        jSpinnerEndDatum.setEditor(editor_end);
    }

    private void initComboBox() {
        try {
            dcbm = new DefaultComboBoxModel();
            jComboBoxBezirk.setModel(dcbm);
            Statement st = (Statement) con.createStatement();
            ResultSet rs = (ResultSet) st.executeQuery("SELECT DISTINCT Bezirk FROM Freie_Mitarbeiter");
            while (rs.next()) {
                dcbm.addElement(rs.getString("Bezirk"));
            }
        } catch (Exception ex) {
        }
    }

    private void initListMA() {
        try {
            dlm_MA = new DefaultListModel();
            jListMA.setModel(dlm_MA);
            Statement st = (Statement) con.createStatement();
            ResultSet rs = (ResultSet) st.executeQuery("SELECT * FROM `Freie_Mitarbeiter` WHERE Bezirk = '" + jComboBoxBezirk.getSelectedItem() + " ' AND `Fuehrerschein` = '" + jComboBoxFuehrerschein.getSelectedItem() + "'");

            while (rs.next()) {
                Mitarbeiter ma = new Mitarbeiter();
                ma.setMa_id(rs.getInt("Mitarbeiter_id"));
                ma.setVorname(rs.getString("Vorname"));
                ma.setNachname(rs.getString("Nachname"));
                ma.setTelefonnummer((rs.getInt("Telefonnummer")));
                ma.setEmail(rs.getString("Email"));
                ma.setBezirk(rs.getString("Bezirk"));
                ma.setGebDatum(rs.getDate("GebDatum"));
                ma.setAusbildung(rs.getString("Ausbildung"));
//                ma.setKonfektionsgröße(rs.getInt("Konfektionsgroeße"));
                ma.setFuehrerschein(rs.getString("Fuehrerschein"));
                ma.setSvnr(rs.getInt("SVNr"));
                ma.setStaatsbuergerschaft(rs.getString("Staatsbuergerschaft"));
                ma.setBankverbindung(rs.getInt("Bankverbindung"));
                ma.setMaart(rs.getString("MAArt"));
                dlm_MA.addElement(ma);
            }
        } catch (Exception ex) {
            Logger.getLogger(bzr_neueVeranstaltung.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void initWerbemittelGiveAways() {
        try {
            dlm_werbemittel = new DefaultListModel();
            jListWerbemittel.setModel(dlm_werbemittel);
            dlm_ga = new DefaultListModel();
            jListGiveAways.setModel(dlm_ga);
            Statement st = (Statement) con.createStatement();
            ResultSet rs = (ResultSet) st.executeQuery("SELECT *FROM `Aussenwerbemittel_Art`");
            while (rs.next()) {
                Werbemittel w = new Werbemittel();
                w.setArt(rs.getString("Aussenwerbemittel_Art"));
                w.setIst_stueckzahl(rs.getInt("Ist_Stueckzahl"));
                dlm_werbemittel.addElement(w);
            }
            ResultSet rs2 = (ResultSet) st.executeQuery("SELECT *FROM GiveAways");
            while (rs2.next()) {
                GiveAway g = new GiveAway();
                g.setName(rs2.getString("Name"));
                g.setIst_stueckzahl(rs2.getInt("Ist_Stueckzahl"));
                dlm_ga.addElement(g);
            }

        } catch (Exception ex) {
            Logger.getLogger(bzr_neueVeranstaltung.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    private void InsertAllgemein() {
        try {
            Date d = (Date) jSpinnerStartDatum.getValue();
            SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
            String dateString = sd.format(d);
            d = (Date) jSpinnerEndDatum.getValue();
            sd = new SimpleDateFormat("yyyy-MM-dd");
            String dateStringEnd = sd.format(d);
            Statement st = (Statement) con.createStatement();
            st.executeUpdate("INSERT INTO Veranstaltungen (Name,Ort,PLZ,Strasse, HausNr,Startdatum,Enddatum,ZustaendigeGeschaeftsstelle)" + "VALUES ('" + jTextFieldName.getText() + "','" + jTextFieldOrt.getText() + "'," + jFormattedTextFieldPLZ.getText() + ",'" + jTextFieldStraße.getText() + "'," + jFormattedTextFieldHnr.getText() + ",'" + dateString + "','" + dateStringEnd + "','" + jTextFieldZustaendigeGeschaeftsstelle.getText() + "')");
            JOptionPane.showMessageDialog(this, "Veranstaltung  " + jTextFieldName.getText() + " wurde erfolgreich erstellt");
        } catch (Exception ex) {
            Logger.getLogger(bzr_neueVeranstaltung.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void InsertMitarbeiter() {
        try {
            Statement st = (Statement) con.createStatement();
             for (int i = 0; i < dlm_aus.size(); i++) {
                 Mitarbeiter m = (Mitarbeiter) dlm_aus.getElementAt(i);
                 st.executeUpdate("INSERT INTO VA_MA VALUES ((SELECT Veranstaltungs_ID FROM Veranstaltungen WHERE Name ='"+ jTextFieldName.getText()+"') ,"+m.getMa_id()+"')");

            }
        } catch (SQLException ex) {
            Logger.getLogger(bzr_neueVeranstaltung.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void InsertWerbemittel() {

    }
}
